﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Mr.Wang.FileLog
{
    public class Util
    {

        public const  string formaterDateTimeOutPut = "yyyy-MM-dd HH:mm:ss.fff";

        /// <summary>
        /// 将文件名中的非法字符替换为'_',得到有效的文件名
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static string GetValidFileName(string filename)
        {
            string newname = filename;
            newname = newname.Replace('/', '_');
            newname = newname.Replace('\\', '_');
            newname = newname.Replace(':', '_');
            newname = newname.Replace('*', '_');
            newname = newname.Replace('?', '_');
            newname = newname.Replace('"', '_');
            newname = newname.Replace('<', '_');
            newname = newname.Replace('>', '_');
            newname = newname.Replace('|', '_');
            newname = newname.Replace((char)0xA, ' ');

            return newname;
        }
    }
}
